#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
//全局变量
int b = 10;
//extern.cpp
extern int c;
//c++的结构体,属性默认是private
typedef struct person
{
private:
	int age = 0;
public:
	string name;
}PERSON,*P_PERSON;

//命名空间
namespace my_space
{
	int a = 4;
}
namespace my_space_2
{
	int a = 6;
	namespace my_space2_1
	{
		int a = 5;
	}
}
//默认参数，默认参数放在最后(函数指针没有默认参数)
void print_a(int a = 0)
{
	cout << a << endl;
}

//测试命名空间,作用域:从当前位置开始到代码结束(如果在块语句内部,只在当前块语句内有效)
using namespace my_space;
void test_namespace()
{
	cout << a << endl;
	cout << my_space_2::a << endl;
	cout << my_space_2::my_space2_1::a << endl;
	namespace b = my_space;
	cout << b::a << endl;

}

//测试结构体
void test_struct()
{
	PERSON p;
	p.name = "张三";
	cout << p.name << endl;
}
//测试全局变量
void test_quanju()
{
	int b = 23;
	cout << b << endl;//23
	cout << ::b << endl; //10
	cout << c << endl;
}
//测试静态
void test_static()
{

	for (int i = 0; i < 10; i++)
	{
		static int a = 10; //只会定义一次，下次直接跳过
		a++;
		cout << a << endl;
	}
}

//函数重载原理
void  print_something(int a)
{
	cout << a << endl;
}
void print_something(int a, int b)
{
	cout << a << endl;
	cout << b << endl;
}

//测试函数重载
void test_overload()
{
	print_something(23);
	print_something(23, 45);

	void(*f1)(int) = print_something;
	void(*f2)(int,int) = print_something;

	cout << f1 << endl;
	cout << f2 << endl;
}
//测试默认参数
void test_default_agrs()
{
	print_a();
	print_a(23);
}



void _4main()
{
	//test_namespace();
	//test_struct();
	//test_quanju();
	//test_static();
	//test_overload();
	test_default_agrs();
	system("pause");
}